﻿using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace CodeContrib.Web.Mvc.Html
{
	public static class ListExtensions
	{
		public static MvcHtmlString List<T>(this HtmlHelper htmlHelper, IEnumerable<T> items, ListType listType)
		{
			string listItemFormat;
			string listFormat;

			switch (listType)
			{
				case ListType.Ordered:
					{
						listFormat = "<ol>{0}</ol>";
						listItemFormat = "<li>{0}</li>";

						break;
					}
				default:
					{
						listFormat = "<ul>{0}</ul>";
						listItemFormat = "<li>{0}</li>";

						break;
					}
			}

			var list = new StringBuilder();

			foreach (var item in items)
			{
				list.AppendFormat(listItemFormat, item);
			}

			return MvcHtmlString.Create(string.Format(listFormat, list));
		}
	}
}